<template>
  <div class="vip-list views-container">
    <div class="wlm-table">
      <div class="wlm-table-hearder-btn">
        <router-link tag="span" to="/application/vipListAdd">
          <el-button size="small" type="primary">添加会员卡</el-button>
        </router-link>
      </div>
      <div class="wlm-table-header">
        <el-form :model="tableFormatData.userTable.files" size="small" label-width="95px" class="retail-form" label-position="right">
          <el-form-item label class="filter">
            <el-form-item label="会员卡名称：">
              <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.card_title" placeholder="请输入会员卡名称" style="width:160px;"></el-input>
            </el-form-item>
            <el-form-item label="会员卡类型：">
              <el-select v-model="tableFormatData.userTable.files.card_type" placeholder="请选择" style="width:200px;">
                <el-option label="全部" value></el-option>
                <el-option label="时间卡" :value="1"></el-option>
                <el-option label="日期卡" :value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否出售：">
              <el-select v-model="tableFormatData.userTable.files.card_is_sell" placeholder="请选择" style="width:200px;">
                <el-option label="全部" value></el-option>
                <el-option label="出售中" :value="1"></el-option>
                <el-option label="停卡中" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-form-item>
          <el-form-item label class="filter-btns">
            <el-button type="primary" @click="filesSerch">筛选</el-button>
            <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="wlm-table-content">
        <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
          <!-- <el-table-column type="selection" width="55">
          </el-table-column>-->
          <el-table-column prop="date" label="排序" min-width="30">
            <template slot-scope="scope">
              <span>{{scope.row.card_sort}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="会员卡名称">
            <template slot-scope="scope">
              <span>{{scope.row.card_title}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="会员卡类型">
            <template slot-scope="scope">
              <span v-if="scope.row.card_type=='1'">时间卡</span>
              <span v-if="scope.row.card_type=='2'">日期卡</span>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="会员卡时长" min-width="90">
            <template slot-scope="scope">
              <div v-if="scope.row.card_type=='1'">
                <p>{{scope.row.card_time_date[0]}}天</p>
              </div>
              <div v-if="scope.row.card_type=='2'">
                <p>{{scope.row.card_time_date[0] | parseTime('{y}-{m}-{d}')}} 至</p>
                <p>{{scope.row.card_time_date[1] | parseTime('{y}-{m}-{d}')}}</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="使用人数">
            <template slot-scope="scope">
              <span>{{scope.row.member_user}}</span>
            </template>
          </el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <span v-if="scope.row.card_state=='1'">未开始</span>
              <span v-if="scope.row.card_state=='2'">使用中</span>
              <span v-if="scope.row.card_state=='3'">已过期</span>
            </template>
          </el-table-column>
          <el-table-column label="是否允许续费">
            <template slot-scope="scope">
              <span>{{scope.row.is_renew === 1 ? '是' : '否'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" min-width="90">
            <template slot-scope="scope">
              <span>{{scope.row.create_time}}</span>
            </template>
          </el-table-column>
          <el-table-column label="是否出售">
            <template slot-scope="scope">
              <el-switch
                :active-value="1"
                :inactive-value="2"
                @change="changeTableItem({id:scope.row.card_id,card_is_sell:scope.row.card_is_sell},tableFormatData.userTable.change.card_is_sell,{isWarning: scope.row.card_is_sell === 2,warning:'确定关闭吗？',cancel:{msg:'已取消关闭',val:{scope:scope,cancelStatus:{key:'card_is_sell',val:1}}}})"
                v-model="scope.row.card_is_sell"
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <div class="operation-group">
                <router-link class="wlm-text" tag="span" :to="{path:'/application/vipListAdd', query :{ id:scope.row.card_id}}">
                  <el-button type="text">编辑</el-button>
                </router-link>
                <div class="btn-line"></div>
                <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.card_id)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-e flex-align-c">
          <!-- <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
          </el-row>-->
          <el-pagination
            :disabled="!hasTableData"
            @size-change="listPageChange"
            @current-change="listPageChange"
            :current-page.sync="tableFormatData.userTable.pagination.page"
            :page-sizes="tableFormatData.userTable.pagination.pagesizes"
            :page-size.sync="tableFormatData.userTable.pagination.list_rows"
            layout="total, sizes, prev, pager, next, jumper"
            :total="hasTableData?tableFormatData.userTable.pagination.total : 0"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getMemberCard,
  delDataCard,
  changeCardSell
} from '@/api/application'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'VipList',
  components: {
  },
  data() {
    return {
      blogTitle: '',
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getMemberCard,
            delList: delDataCard
            //   msgConfig: {
            //     del: {
            //       type: 'warning',
            //       msg: '此操作会删除用户的所有数据，名下所有平台内如有正在交易的订单、金额，删除后所产生的纠纷由服务商自身承担 如要删除请慎重操作！！'
            //     }
            //   }
          },
          tableData: [],
          files: {
            card_type: '',
            card_title: '',
            card_is_sell: '',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          change: {
            card_is_sell: {
              key: 'card_is_sell',
              api: changeCardSell
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  created(){
    console.log('store___________________',this.$store);
  },
  methods: {
  }
}
</script>
